//
//  ChargeOnlineView.m
//  aiteshangcheng
//
//  Created by caominglei on 2018/4/24.
//  Copyright © 2018年 aite. All rights reserved.
//

#import "ChargeOnlineView.h"
#import "UIImage+Category.h"
@interface ChargeOnlineView ()<UITextFieldDelegate>
@property (strong, nonatomic) UILabel *title;
@property (strong, nonatomic) UIButton *commitBtn;
@end
@implementation ChargeOnlineView


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        [self createSubviews];
        [self createSubviewsFrame];
        
    }
    return self;
}
- (void)createSubviews
{
    
    UILabel *title = [YCCommonCtrl commonLableWithFrame:CGRectZero text:@"*充值金额" color:[UIColor blackColor] font: [UIFont systemFontOfSize:10] textAlignment:NSTextAlignmentLeft];
    [self addSubview:title];
    self.title = title;
    
    UITextField *field = [YCCommonCtrl commonTextFieldWithFrame:CGRectZero placeholder:@"" color:[UIColor blackColor] font:[UIFont systemFontOfSize:12] secureTextEntry:NO delegate:self];
    field.layer.cornerRadius = 4;
    field.clipsToBounds = YES;
    field.layer.borderColor = [UIColor grayColor].CGColor;
    field.layer.borderWidth = 1;
    field.delegate = self;
    field.returnKeyType = UIReturnKeyDone;
    [self addSubview:field];
    self.field = field;
    
    UIButton *commitBtn = [YCCommonCtrl commonButtonWithFrame:CGRectZero title:@"提交" color:[UIColor whiteColor] font:[UIFont systemFontOfSize:12] backgroundImage:[UIImage createImageWithColor:[UIColor redColor]] target:self action:@selector(rechargeRequest:)];
    commitBtn.backgroundColor = [UIColor redColor];
    commitBtn.layer.cornerRadius = 4;
    commitBtn.clipsToBounds = YES;
    commitBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [commitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self addSubview:commitBtn];
    self.commitBtn = commitBtn;
}

- (void)rechargeRequest:(UIButton *)button
{
    if ([self.delegate respondsToSelector:@selector(chargeCommitWithTextString:)]) {
        [self.delegate chargeCommitWithTextString:self.field.text];
    }
}
- (void)createSubviewsFrame
{
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30);
        make.top.mas_equalTo(10);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(75);
    }];
    
    [self.field mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.title.mas_right).offset(0);
        make.top.mas_equalTo(10);
        make.height.mas_equalTo(40);
        make.right.mas_equalTo(-15);
    }];
    
    
    [self.commitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.field.mas_bottom).offset(30);
        make.left.mas_equalTo((kScreenWidth - 150)/2);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(150);
    }];
}
@end
